package com.xmy.solution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.xmy.solution.domain.dto.solution.SolutionAppReqDTO;
import com.xmy.solution.domain.dto.solution.SolutionAppResDTO;
import com.xmy.solution.domain.dto.solution.SolutionReqDTO;
import com.xmy.solution.domain.dto.solution.SolutionsPageDTO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.xmy.common.annotation.Log;
import com.xmy.common.core.controller.BaseController;
import com.xmy.common.core.domain.AjaxResult;
import com.xmy.common.enums.BusinessType;
import com.xmy.solution.domain.Solutions;
import com.xmy.solution.service.IsolutionsService;
import com.xmy.common.utils.poi.ExcelUtil;
import com.xmy.common.core.page.TableDataInfo;

/**
 * 方案管理Controller
 *
 * @author 夏明毅
 * @date 2024-12-29
 */
@RestController
@RequestMapping("/solution/solutions")
public class solutionsController extends BaseController {
    @Autowired
    private IsolutionsService solutionsService;

    /**
     * 查询方案管理列表
     */
    @PreAuthorize("@ss.hasPermi('solution:solutions:list')")
    @GetMapping("/list")
    public TableDataInfo list(SolutionsPageDTO solutions) {
        startPage();
        List<SolutionReqDTO> list = solutionsService.selectSolutionsVOList(solutions);
        return getDataTable(list);
    }

    @PostMapping("/AppList")
    public TableDataInfo appList(@RequestBody SolutionAppReqDTO solutions) {
        PageHelper.startPage(solutions.getPageNum(), solutions.getPageSize()).setReasonable(true);
        List<SolutionAppResDTO> list = solutionsService.selectSolutionAppReqDTOList(solutions);
        return getDataTable(list);
    }

    /**
     * 导出方案管理列表
     */
    @PreAuthorize("@ss.hasPermi('solution:solutions:export')")
    @Log(title = "方案管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Solutions solutions) {
        List<Solutions> list = solutionsService.selectSolutionsList(solutions);
        ExcelUtil<Solutions> util = new ExcelUtil<Solutions>(Solutions.class);
        util.exportExcel(response, list, "方案管理数据");
    }

    /**
     * 获取方案管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('solution:solutions:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(solutionsService.selectSolutionsById(id));
    }

    /**
     * 小程序获取方案信息
     *
     * @param id
     * @return
     */
    @GetMapping(value = "/get")
    public AjaxResult AppGetInfo(@RequestParam("id") Long id, @RequestParam(value = "userId",required = false) Long userId) {
        return success(solutionsService.selectAppSolutionsById(id ,userId));
    }

    /**
     * 新增方案管理
     */
    @PreAuthorize("@ss.hasPermi('solution:solutions:add')")
    @Log(title = "方案管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SolutionReqDTO solutions) {
        return toAjax(solutionsService.insertSolutions(solutions));
    }

    /**
     * 修改方案管理
     */
    @PreAuthorize("@ss.hasPermi('solution:solutions:edit')")
    @Log(title = "方案管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SolutionReqDTO solutions) {
        return toAjax(solutionsService.updateSolutions(solutions));
    }

    /**
     * 删除方案管理
     */
    @PreAuthorize("@ss.hasPermi('solution:solutions:remove')")
    @Log(title = "方案管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(solutionsService.deleteSolutionsByIds(ids));
    }


}
